﻿// -----------------------------------------------------------------------------------------------
//  <copyright file="TfsConfig.cs" company="http://buginbox.wordpress.com/">
//    Copyright (c) GNU General Public License version 2 (GPLv2)
//  </copyright>
// -----------------------------------------------------------------------------------------------

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.TestManagement.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace TestPlanMigration
{
    /// <summary>
    /// The tfs config.
    /// </summary>
    public class TfsConfig
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="TfsConfig"/> class. Prevents a default instance of the <see cref="TfsConfig"/> class from being created.
        /// </summary>
        /// <param name="projectCollection">The project collection.</param>
        /// <param name="workItemStore">The work item store.</param>
        /// <param name="testService">The test service.</param>
        private TfsConfig(TfsTeamProjectCollection projectCollection, WorkItemStore workItemStore, ITestManagementService testService)
        {
            ProjectCollection = projectCollection;
            WorkItemStore = workItemStore;
            TestService = testService;
        }

        /// <summary>
        /// Gets the project collection.
        /// </summary>
        public TfsTeamProjectCollection ProjectCollection { get; private set; }

        /// <summary>
        /// Gets the work item store.
        /// </summary>
        /// <value>
        /// The work item store.
        /// </value>
        public WorkItemStore WorkItemStore { get; private set; }

        /// <summary>
        /// Gets the test service.
        /// </summary>
        /// <value>
        /// The test service.
        /// </value>
        public ITestManagementService TestService { get; private set; }

        /// <summary>
        /// News the configuration.
        /// </summary>
        /// <param name="projectCollection">The project collection.</param>
        /// <returns></returns>
        public static TfsConfig NewConfiguration(TfsTeamProjectCollection projectCollection)
        {
            var store = (WorkItemStore)projectCollection.GetService(typeof(WorkItemStore));
            var service = (ITestManagementService)projectCollection.GetService(typeof(ITestManagementService));
            return new TfsConfig(projectCollection, store, service);
        }
    }
}